package org.redmaple.core.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.redmaple.core.support.Page;
import org.redmaple.core.template.dto.BaseDTO;
import org.redmaple.core.template.model.BaseModel;

/**
 * 用于发送分页信息到前台的对象封装，经过JSON进行转换后通过DataGrid可在前台展示
 * 
 * @author Xiangyun
 *
 * @param <T>
 */
@SuppressWarnings("serial")
public class PageData<T extends BaseDTO> implements Serializable {
	
	private long total = 0;
	private List<T> rows = new ArrayList<T>();
	
	public PageData() {
		
	}
	
	public PageData(Page<? extends BaseModel> page, Class<T> clazzT) {
		total = page.getTotalRecords();
		T object = null;
		try{
			for(BaseModel model : page.getResult()) {
				object = clazzT.newInstance().convert(model);
				rows.add(object);
			}
		}catch (IllegalAccessException e) {
			e.printStackTrace();
		}catch (InstantiationException e) {
			e.printStackTrace();
		}
	}

	public PageData(long total, List<T> rows) {
		this.total = total;
		this.rows = rows;
	}
	
	public long getTotal() {
		return total;
	}
	public void setTotal(long total) {
		this.total = total;
	}
	public List<T> getRows() {
		return rows;
	}
	public void setRows(List<T> rows) {
		this.rows = rows;
	}
	
	
}
